package game_event

import (
	"base"
	"errors"
	"fmt"
)

type (
	closeEvent struct {
	}
	closeCallback = func(players []base.PlayerId)
)

var OnClose = new(closeEvent)

func (event *closeEvent) Verify(callback interface{}) (err error) {
	if _, ok := callback.(closeCallback); !ok {
		err = errors.New("not close event callback function")
	}

	return
}

func (event *closeEvent) Call(callback interface{}, args []interface{}) (err error) {
	const ArgsCount = 1
	if len(args) < ArgsCount {
		err = fmt.Errorf("close event callback need %d arg", ArgsCount)
		return
	}

	call := callback.(closeCallback)
	i := 0
	players := args[i].([]base.PlayerId)
	i++

	call(players)

	return
}
